<?php

namespace Ihanpy\Core;

class Route
{
    public $controller = null;
    public $action = null;

    public function __construct()
    {
        // /index/index
        if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/') {
            $urlPath = $_SERVER['REQUEST_URI'];
            $urlPath = ltrim($urlPath, '/');
            $pathArr = explode('/', $urlPath);
            if (isset($pathArr[0])) {
                $this->controller = $pathArr[0];
            }
            if (isset($pathArr[1])) {
                $this->action = $pathArr[1];
            }
        } else {
            $this->controller = 'index';
            $this->action = 'index';
        }

        // todo 还需要考虑一下get参数的问题,比如 /index/index/id/1/name/hanpy
    }
}